package com.aletto.general_store.ui.activities;

import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.RecyclerView;

import com.aletto.general_store.R;
import com.aletto.general_store.data.DataRepository;
import com.aletto.general_store.presenters.HistoryPageTemplate;
import com.aletto.general_store.presenters.core.SimpleTemplate;
import com.aletto.general_store.ui.popup.AddChainNodePopup;
import com.aletto.general_store.ui.popup.ConfirmHistoryPopup;
import com.aletto.general_store.utils.XHelper;
import com.lxj.xpopup.XPopup;
import com.scwang.smart.refresh.layout.SmartRefreshLayout;
import com.sisyphus.spinach.core.INetTask;
import com.sisyphus.spinach.network.presenters.NetSingleTask;

/**
 * 浏览历史
 */
public class BrowserHistoryActivity extends AppCompatActivity {

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_browser_history);
        XHelper.initTitle(this, R.string.title_browser_history);

        RecyclerView recyclerView = findViewById(com.sisyphus.spinach.R.id.recycler_view);
        SmartRefreshLayout refreshLayout = findViewById(com.sisyphus.spinach.R.id.refresh_layout);

        new HistoryPageTemplate(recyclerView, refreshLayout).execute(getLifecycle());

        findViewById(R.id.tv_clear_history).setOnClickListener(v -> {

            RecyclerView.Adapter adapter = recyclerView.getAdapter();
            if (adapter != null && adapter.getItemCount() > 1) { // 空布局
                ConfirmHistoryPopup popup = new ConfirmHistoryPopup(v.getContext());
                popup.setRecyclerView(recyclerView);
                new XPopup.Builder(v.getContext()).asCustom(popup).show();
            }

        });
    }

}
